package com.finace.money.ui.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangpeng on 2017/11/23.
 */

public class MainViewPagerAdapter extends PagerAdapter {

    private List<View> mDatas;
    private List<String> mTitles;

    public MainViewPagerAdapter(List<View> data,List<String> titles) {
        this.mDatas = data;
        this.mTitles = titles;
    }

    @Override
    public int getCount() {
        return null != mDatas && mDatas.size() > 0 ? mDatas.size() : 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        ViewGroup parent = (ViewGroup) mDatas.get(position).getParent();
        if(parent != null){
            parent.removeView(mDatas.get(position));
        }
        container.addView(mDatas.get(position));
        return mDatas.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

        container.removeView(mDatas.get(position));
    }

    @Override
    public CharSequence getPageTitle(int position) {
        /*switch (position) {
            case 0:
                return "";
            case 1:
                return "交易攻略";
            case 2:
                return "行业咨询";
        }*/
        return mTitles.get(position);
    }
}
